package com.travelSpring.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.travelSpring.common.Result;
import com.travelSpring.pojo.entity.Scenic;
import com.travelSpring.pojo.vo.ScenicVO;
import com.travelSpring.service.ProductAutoExtendService;
import com.travelSpring.service.ScenicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 功能：
 * 作者：卷心菜
 * 日期：2025/5/8 10:02
 */

@RestController
@RequestMapping("/scenic")
public class ScenicPublicController {

    @Autowired
    ScenicService scenicService;

    @Autowired
    ProductAutoExtendService productAutoExtendService;
    /**
     * 手动触发自动延期（测试/紧急情况下使用）
     */
    @GetMapping("/forceUpdateStatus")
    public Result forceUpdateStatus() {
        productAutoExtendService.batchUpdateStatus(); // 手动触发
        productAutoExtendService.autoExtendProduct();
        return Result.success("状态已强制更新");
    }

    @GetMapping("/selectAll")
    public Result selectAll(Scenic scenic) {
        List<Scenic> scenics = scenicService.selectAll(scenic);
        return Result.success(scenics);
    }

    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Scenic scenic = scenicService.selectById(id);
        return Result.success(scenic);
    }

    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "8") Integer pageSize,
                             Scenic scenic
    ){
        IPage<ScenicVO> iPage = scenicService.selectPage(pageNum,pageSize, scenic);
        return Result.success(iPage);
    }
}
